package com.longdaji.decoration.ui.activitiesOfMine.pendingReceiving;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.longdaji.decoration.Constants;
import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseActivity;
import com.longdaji.decoration.bean.Collection;
import com.longdaji.decoration.bean.Logistics;
import com.longdaji.decoration.bean.MyLogistics;
import com.longdaji.decoration.bean.Orders;
import com.longdaji.decoration.adapter.SeeLogisticsAdapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SeeLogisticsActivity extends BaseActivity implements SeeLogisticsContract.IView {

    @Inject
    SeeLogisticsContract.IPresenter mPresenter;
    @BindView(R.id.tv_tool_title)
    TextView tvTitle;
    @BindView(R.id.rv_logistics)
    RecyclerView rvLogistics;
    @BindView(R.id.tv_shipping_type)
    TextView tvShippingType;
    @BindView(R.id.tv_shipping_number)
    TextView tvShippingNumber;
    @BindView(R.id.tv_receiving_address)
    TextView tvReceivingAddress;

    private String orderNo;
    private SeeLogisticsAdapter mAdatper;
    private List<MyLogistics.TracesBean> mLogistics = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_see_logistics);

        setUnBinder(ButterKnife.bind(this));
        if (mPresenter != null)
            mPresenter.setView(this);
        tvTitle.setText("查看物流");

        initView();

    }

    private void initView() {
//        initLogistics();
        orderNo = getIntent().getStringExtra(Constants.ORDER_NO);
        mAdatper = new SeeLogisticsAdapter(mLogistics);
        rvLogistics.setAdapter(mAdatper);
        rvLogistics.setLayoutManager(new LinearLayoutManager(this));
        mPresenter.initOrder(orderNo);

    }

//    private void initLogistics() {
//        Logistics logistics = new Logistics("10-11", "01:20", "已发货", "1111111111111111111");
//        mLogistics.add(logistics);
//        Logistics logistics2 = new Logistics("10-11", "01:25", "派送中", "22222222222222222222");
//        mLogistics.add(logistics2);
//        Logistics logistics3 = new Logistics("10-11", "02:20", "派送中", "3333333333333333333");
//        mLogistics.add(logistics3);
//        Logistics logistics4 = new Logistics("10-13", "11:20", "派送中", "444444444444444444");
//        mLogistics.add(logistics4);
//        Logistics logistics5 = new Logistics("10-14", "14:30", "已签收", "555555555555555555555");
//        mLogistics.add(logistics5);
//
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }

    @OnClick({R.id.rl_tool_back})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_tool_back:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    public void showInitLogistics(MyLogistics myLogistics) {
        Collections.reverse(myLogistics.getTraces());
        this.mAdatper.setData(myLogistics.getTraces());
        String shipperType = "";
        switch (myLogistics.getShipperCode()) {
            case "SF":
                shipperType = "顺丰速运";
                break;
            case "HTKY":
                shipperType = "百世快递";
                break;
            case "ZTO":
                shipperType = "中通快递";
                break;
            case "STO":
                shipperType = "申通快递";
                break;
            case "YTO":
                shipperType = "圆通快递";
                break;
            case "YZPY":
                shipperType = "邮政快递包裹";
                break;
            case "EMS":
                shipperType = "EMS";
                break;
            case "HHTT":
                shipperType = "天天快递";
                break;
            default:
                shipperType = "其它快递";
                break;
        }
        tvShippingType.setText(shipperType);
        tvShippingNumber.setText(myLogistics.getShipperCode());
//        tvReceivingAddress.setText(myLogistics.);
    }
}
